import http from './http.js';
var api = {}

api.getIndex = function( cb ){
  http.doGet("/index" , {} , function( response ){
    if(response.data.status ==1){
      cb(response.data);
    }else{
      wx.showToast({
        title: response.data.message
      })
    }
  })
}



api.getMerchantInfo = function(params , cb) {

  http.doGet("/setting/getMerchantInfo" , params , function (response) {
    cb(response.data);
  })
  
}

api.getCartProductSums = function( params , cb ){
  http.doGet("/index/getCartProductNums"  ,  params , function(response){
    cb(response.data)
  });
}

api.getAppMessageList = function( params , cb ){
  http.doGet("/index/getAppMessageList" , params , function( response ){
    cb(response.data)
  })

}



var product = {}
/**
 * 加载商品列表
 */
product.getProductList = function( cb ){

  http.doGet("/index" , {} , function( response ){
    if(response.data.status ==1){
      cb(response.data);
    }else{
      wx.showToast({
        title: response.data.message
      })
    }
  })
}
product.getProductSku = function(params , cb ){
  http.doGet("/product/getProductSku" ,  params, function(response){
    cb(response.data)
  })
}


product.searchProduct = function( params , cb ){
  http.doPost("/product/searchProduct" , params , function(response){
    cb(response.data)
  })
}
product.getProductDetail = function(params , cb){
  http.doGet("/product/detail" , params , function(response){
    cb(response.data)
  })
}

product.getCategoryList = function (params ,cb) {
  http.doPost("/product/getCategoryList" , params , function (response) {
    cb(response.data)
  })
}

product.getCategoryIndexData= function (params, cb) {
  http.doGet("/product/getCategoryIndexData" , params , function(response) {
    cb( response.data );
  })
}

/**
 * 加载产品列表
 */
product.getCategoryProductList = function( params,  cb){
  http.doGet("/index/getCategoryProductList" , {} , function( response ){
    cb(response.data);
  })
}

product.getProductCommentList = function( params  ,cb ){
  http.doGet("/product/getProductCommentList", params,  function (response) {
    cb( response.data )
  })
}

product.getProductListByCategory = function( params , cb ){
  http.doGet("/product/getProductListByCategory" , params , function( response ){
    cb( response.data );
  })
}




/**
 * 新增收获地址
 */
api.addAddress = function( data , cb ){
  http.doPost("/address/add" , data , function( response ){
    cb(response.data)
  })
}

/**
 * 加载用户地址列表
 */
api.getAddressList = function(cb){
  http.doGet("/address/getList"  , {} , function( response ){
    cb(response.data)
  });
}

api.getAddressDetail = function( params , cb ){
  http.doGet("/address/getAddressDetail" , params , function( response){
    cb(response.data)
  })
}

api.setDefaultAddress = function(params , cb){
  http.doGet("/address/setDefaultAddress" , params,  function( response ){
    cb(response.data)
  })
}

api.getDefaultAddress = function( params , cb ){
  http.doGet("/address/getDefaultAddress" , {} , function( response ){
    cb(response.data)
  })
}
/**
 * 
 * @param {*} params 
 * @param {*} cb 
 */
api.removeAddress = function(params , cb){
  http.doGet("/address/removeAddress" , params , function( response ){
    cb( response.data )
  })
}


api.getAppInfo = function(params , cb){
  http.doGet("/index/info" , params , function(response){
    cb(response.data);
  });
}


api.getRedPacket = function(params ,cb){
  http.doGet("/activity/getRedPacket" , params , function( response ){
    cb(response.data);
  })
}

var order = {};
order.getOrderList = function( data , cb ){
  http.doGet("/order/getOrderList" , params , function( response ){
    cb(response.data);
  })
}

order.createOrder = function(data , cb){
  http.doPost("/order/createOrder4" , data , function( response ){
    cb(response.data);
  })
}

order.getOrderProductCommentList = function( params , cb ){
  http.doGet("/order/getOrderProductCommentList" , params , function( response ){
    cb(response.data)
  })
}

order.submitProductComment = function( data , cb ){
  http.doPost("/order/saveProductComment" , data , function(response){
    cb(response.data)
  })
}
order.getOrderPrepare = function (params , cb) {
  http.doGet("/order/getOrderPrepare" , params , function (response) {
    cb(response.data);
  } , true)
}



api.order = order;

/**
 * 加载订单列表
 */
api.getOrderList = function(params , cb){
  http.doGet("/order/getOrderList" , params , function( response ){
    cb(response.data);
  })

}
/**
 * 创建订单
 * @param {*} params 
 * @param {*} cb 
 */
api.createOrder = function(data , cb){
  http.doPost("/order/create" , data , function( response ){
    cb(response.data)
  })
}

api.getOrderDetail = function(params , cb){
  http.doGet("/order/detail" , params , function(response){
    cb( response.data )
  })
}

api.getOrderProducts = function(params , cb) {
  http.doGet("/order/getOrderProducts" , params , function name(respponse) {
    cb(respponse.data)
  })
  
}

api.doOrderCancel = function( params , cb ){
  http.doGet("/order/doOrderCancel" , params , function(response){
    cb(response.data)
  });
}
/**
 * 支付订单
 * @param {*} params 
 * @param {*} cb 
 */
api.doPay = function( params , cb ){
  http.doGet("/order/doPay" , params  , function(response){
    cb(response.data);
  })
}

//处理订单完成
api.doOrderComplete = function( params , cb){
  http.doGet("/order/doOrderComplete" , params , function(response){
    cb(response.data)
  })
}
//评价
api.doOrderComment = function( data , cb ){
  http.doPost("/order/doOrderComment" , data , function(response){
    cb(response.data);

  })
}
//加载活动列表
api.getActivityList = function(data , cb){
  http.doPost("/activity/index" , data , function(response){
    cb(response.data);
  })
}

api.getActivityDetail = function( data  , cb){

  http.doGet("/activity/detail" , data , function( response ){
    cb(response.data);
  })
}

api.getActivityContent = function( params , cb ){
  http.doGet("/activity/getActivityContent" , params , function( response ){
    cb(response.data);
  })
}

api.getActivityInfo = function(params , cb){
  http.doGet("/activity/getActivityInfo" , params , function(response){
    cb(response.data);
  })
}

api.doActivityHandler = function(params , cb){

  http.doGet("/activity/doActivityHandler" , params, function(response){
    cb(response.data)
  })
}



/**
 * 加载邀请好友设置
 */
api.getInviteInfo = function( data , cb ){

  http.doPost("/activity/getInviteFriend" , function(response){
    cb(response.data);
  })

}




var coupou = {}

//加载优惠券
coupou.getCoupouList = function(data , cb){
  http.doGet("/coupou/getCoupouList" , data , function( response ){
    cb(response.data)
  })
}


coupou.getCoupouDetail = function(params  , cb){
  http.doGet("/coupou/getCoupouDetail" , params , function( response ){
    cb(response.data)
  })
}

//加载优惠券
api.getCoupouList = function(data , cb){
  http.doGet("/coupou/getCoupouList" , data , function( response ){
    cb(response.data)
  })
}






//加载用户优惠券
api.getUserCoupouList = function(data , cb){
  http.doGet("/usercoupou/getUserCoupouList" , data , function( response ){
    cb(response.data);
  })
}

api.getUserCanUseCoupouList = function (params , cb) {
  http.doGet("/usercoupou/getUserCanUseCoupouList" , params , function (response) {
    cb( response.data )
  })
}

//领取优惠券
api.getCoupou = function(data , cb){
  http.doGet("/usercoupou/getCoupou" , data , function(response){
    cb(response.data)
  })
}
//加载省份列表
api.getProvinceList = function( data , cb){
  http.doGet("/position/getProvinceList" , {} , function( response ){
    cb(response.data)
  })
}
/**
 * 加载城市列表
 * @param {*} params 
 */
api.getCityList = function(params , cb){
  http.doGet("/position/getCityList" , params , function( response ){
    cb(response.data);
  })
}

api.getAreaList = function( params ,cb ){
  http.doGet("/position/getAreaList" , params , function(response){
    cb(response.data);
  })
}


var cart = {};
//加载购物车列表
cart.getProductList = function(data ,  cb ){
  http.doGet("/cart/getProductList" , {} , function( response ){
    cb(response.data);
  })
}
//添加商品
cart.addProduct = function(data , cb){
  http.doGet("/cart/addProduct" , data , function(response){
    cb(response.data);
  })
}

cart.addSkuToCart = function (params , cb) {
  http.doPost("/cart/addSkuToCart" , params , function (response) {
    cb(response.data);
  })
  
}

cart.addCartProduct = function (params , cb) {
  http.doGet("/cart/addCartProduct" , params , function (response) {
    cb(response.data);
    
  })
  
}
//移除商品
cart.removeProduct = function(data , cb){
  http.doGet("/cart/removeProduct" , data , function(response){
    cb(response.data);
  })
}

cart.reduceProduct = function(data , cb){
  http.doGet("/cart/reduceProduct" , data , function(response){
    cb(response.data);
  })
}
//清空购物车
cart.clear = function(data , cb){
  http.doGet("/cart/clear" , {} , function(response){
    cb(response);
  })
}



api.cart = cart;


var user = {}

user.doLoginByUsername = function (data , cb) {
  http.doPost("/sign/doLoginByUsername" ,  data , function (response) {
    cb(response.data)
  })
}

user.doRegisterByUsername = function (data , cb) {
  http.doPost("/sign/doRegisterByUsername" , data , function (response) {
    cb(response.data);
    
  })
  
}
//加载用户中心数据
user.getIndex = function(data , cb){
  http.doGet("/user/index" , {} , function(response){
    cb(response.data);
  })
}
//加载商店系统  用户中心 首页数据 
user.getShopUserIndex = function (data , cb) {
    http.doGet("/user/getShopUserIndex" , {} , function (response) {
        cb( response.data )
    })
}

user.getUserProductCommentList = function( data ,cb){
  http.doGet("/user/getUserProductCommentList" , {} , function(response){
    cb(response.data)
  })
}

user.getUserInfo =function( params , cb ){
  http.doGet("/user/getUserInfo" , {}, function (response) {
    cb(response.data)
  });
}

user.changeMobile = function (params , cb) {
  http.doGet("/user/changeMobile" , params , function(response) {
    cb(response.data)
  })
}
//加载门店订单统计
user.getUserShopOrderSummary = function (params , cb) {
  http.doGet("/user/getUserShopOrderSummary" , params , function ( response ) {
    cb( response.data )
  })
}

user.changeNickName = function( params , cb ){

}

user.changeUserIcon = function( tempFilePath , params  , cb ){
  http.doUploadFile("/user/changeUserIcon" , tempFilePath , params ,cb )
}

user.uploadCommentImage = function( tempFilePath , params , cb ){
  http.doUploadFile("/common/upload" , tempFilePath , params ,cb )

}

user.openSubscribeMessage = function( data , cb ){
  http.doPost("/index/openSubscribbeMessage" , data , cb)
}

user.getSubscribeList = function(params , cb){
  http.doGet("/index/getSubscribeList" , params , function(response){
    cb(response.data)
  })
}

user.getCoupou = function (params , cb) {
  http.doGet("/usercoupou/getCoupou" , params , function( response ){
    cb( respponse.data )
  })
}

api.doLogin = function(data , cb){
  http.doPost("/sign/login" ,  data , function(response){
    cb(response.data)
  })
}



var activity = {}
//接受邀请
activity.acceptInvite = function( params , cb ){
  http.doGet("/activity/acceptInvite" , params , function( cb ){
    cb(response.data);
  })
}




var retail = {

}

retail.doRetailApplay = function( data , cb ){
  http.doPost("/retail/doApply" , data , function(response){
    cb(response.data)
  })
}
/**
 * 加载分销店铺信息
 */
retail.getIndex = function( data ,cb ){
  http.doPost("/retail/index" , data , function( response ){
    cb(response.data)
  })
}

retail.getRetailUserOrderList = function( params , cb ){
  http.doGet("/retail/getRetailUserOrderList" , params , function (response) {
    cb(response.data) 
  })
}

retail.getRetailUserExtractList = function (params , cb) {
  http.doGet("/retail/getRetailUserExtractList"  , params , function ( response ) {
    cb( response.data )
  })
  
}

retail.getRetailUserExtractInfo = function (params , cb) {
  http.doGet("/retail/getRetailUserExtractInfo" , params, function (response) {
    cb(response.data)
  })
}
//加载分销商 收款银行卡列表
retail.getRetailUserBankList = function (params , cb) {
  http.doGet("/retail/getRetailUserBankList" , params , function (response) {
    cb(response.data)
  })
}

retail.addRetailUserBank = function (data , cb) {
  http.doPost("/retail/addRetailUserBank" , data , function (response) {
    cb( response.data )
  })
  
}

retail.getRetailOrderDetail = function( params , cb ){
  http.doGet("/retail/getRetailOrderDetail" , params , function (response) {
    cb( response.data );
  })
}

/**
 * 加载店铺可分销商品列表
 * @param {*} params 
 * @param {*} cb 
 */
retail.getRetailProductList  = function (params , cb) {
  http.doGet("/retail/getRetailProductList" , params , function (response) {
    cb(response.data)
    
  })
  
}

/**
 * 加载分销商店铺商品信息
 */

 retail.getUserRetailProductList = function ( params , cb) {
   http.doGet("/retail/getUserRetailProductList" , params ,function (response) {
     cb(response.data);
   })
 }

 retail.addUserRetailProduct = function (params , cb) {
   http.doGet("/retail/addUserRetailProduct" , params , function ( response ){
     cb(response.data)
   })  
}


retail.removeUserRetailProduct = function (params , cb) {
  http.doGet("/retail/removeUserRetailProduct" , params , function ( response ){
    cb(response.data)
  })  
}

retail.createShopQrcode = function (params , cb) {
  http.doGet("/retail/createShopQrcode" , params , function (response) {
    cb(response.data)
  })
  
}


retail.getRetailShopInfo = function (params , cb) {
   http.doGet("/retail/getRetailShopInfo" , params , function (response) {
     cb(response.data);
   })
}

//加载店铺首页信息设置
retail.getRetailShopIndexData = function( params , cb ){
  http.doGet("/retail/getRetailShopIndexData" , params , function( response ){
    cb(response.data)
  })
}
retail.doRetailExtract = function (data , cb) {
  http.doPost("/retail/doRetailExtract" , data , function( response ){
    cb(response.data)
  })
}



var cash = {

}

cash.getIndex = function( data , cb ){
  http.doPost("/usercash/index" , {} , function(response){
    cb(response.data)
  })
}


var setting = {}
setting.getCustomerList = function( params , cb ){
  http.doGet("/setting/getCustomerList" , {} , function(response){
    cb(response.data)
  })
};

setting.getCompanyInfo = function( params , cb ){
  http.doGet("/setting/getCompanyInfo" , {} , function(response){
    cb(response.data)
  })

}
setting.getMerchantPermitList = function (params , cb) {
  http.doGet("/setting/getMerchantPermitList" , params , function (response) {
    cb( response.data );
  })
}


var refund = {}

refund.getRefundReasonList = function (params , cb) {
  http.doGet("/refund/getRefundReasonList" , params , function (response) {
    cb(response.data)
  })
  
}

refund.createRefundOrder = function (data , cb ) {
  http.doPost("/refund/createRefundOrder" , data , function (response) {
    cb(response.data)
  } , true)
}
refund.getRefundOrderList = function (params , cb) {
  http.doGet("/refund/getRefundOrderList" , params , function (response) {
    cb(response.data)
    
  } , true)
  
}
/**
 * 加载售后申请单详情
 * @param {*} params 
 * @param {*} cb 
 */
refund.getRefundDetail = function (params , cb) {
  http.doGet("/refund/getRefundDetail" , params , function ( response) {
    cb(response.data)
  })
  
}
/**
 * 保存寄回商品快递信息
 * @param {*} data 
 * @param {*} cb 
 */
refund.saveSendBackInfo = function (data , cb) {
  http.doPost("/refund/saveSendBackInfo" , data , function (response) {
    cb(response.data);
  })
}

var article = {};
article.getArticleList = function (params , cb) {

  http.doGet("/article/getArticleList" , params , function (response) {
    cb(response.data);
  })
}

article.getArticleDetail = function (params , cb) {
  http.doGet("/article/getArticleDetail" , params , function (response) {
    cb(response.data)
  })
}



//小店 超市接口
var shop = {}
shop.getShopIndexData = function (params , cb) {
  http.doGet("/market/getShopIndexData" , params, function (response) {
    cb(response.data)
  })
}

shop.getProductListByCategory = function( params , cb ){
  //
  http.doGet("/market/getProductListByCategory" , params ,function ( response ) {
    cb( response.data )
  })
}
//加载店铺评价数据
shop.getShopCommentIndex = function (params , cb) {
  http.doGet("/market/getShopCommentIndex" , params , function (response) {
    cb( response.data)
  })
  
}


//加载店铺评论列表
shop.getShopCommentList = function (params , cb) {
  http.doGet("/market/getShopCommentList" , params , function (response) {
    cb( response.data )
  })
}

shop.getShopSetting  = function (params , cb) {
  http.doGet("/market/getShopSetting" , params , function (response) {
    cb(response.data)
  })
}

shop.getUserShopOrderList = function (params , cb) {
  http.doGet( "/marketOrder/getUserShopOrderList" ,  params ,  function (response) {
    cb(response.data); 
  })
}

shop.getShopOrderDetail = function (params , cb) {
  http.doGet("/marketOrder/getShopOrderDetail" , params , function (response) {
    cb(response.data)
  })
}
shop.doShopOrderCancel = function (params , cb) {
  http.doGet("/marketOrder/doShopOrderCancel" , params , function (response) {
    cb( response.data );
  })
}

shop.doShopOrderPay = function (params , cb) {
  http.doGet("/marketOrder/doMarketOrderPay" , params , function (response) {
    cb( response.data )
  })
}

shop.doShopOrderComplete = function (params , cb) {
  http.doGet("/marketOrder/doShopOrderComplete" , params , function (response) {
    cb( response.data )
  })
}

shop.submitShopOrderComment = function (data , cb) {
  http.doPost("/marketOrder/submitShopOrderComment" , data , function (response) {
    cb( response.data )
  })
}

shop.getUserShopOrderNoCommentList = function (params , cb) {
  http.doGet("/marketOrder/getUserShopOrderNoCommentList" , params , function (response) {
    cb( response.data );
  })
}

shop.getUserShopOrderCommentList = function (params , cb) {
  http.doGet("/marketOrder/getUserShopOrderCommentList" , params , function (response) {
    cb(response.data);
  })
  
}

shop.getMarketSetting = function( params , cb ){
  http.doGet("/market/getMarketSetting" , params , function(response){
    cb(response.data)
  })

}
/**
 * 添加商品购物车
 * @param {*} params 
 * @param {*} cb 
 */
shop.addProductToCart = function(  params , cb){
    http.doGet("/marketCart/addGood" , params , function( response ){
        if(response.data.status ==1){
          cb(response.data);
        }else{
          wx.showToast({
            title: response.data.message
          })
        }
      })
}

shop.reduceProductToCart = function( params , cb ){

  http.doGet("/marketCart/reduceGood" , params , function( response ){
    if(response.data.status ==1){
      cb(response.data);
    }else{
      wx.showToast({
        title: response.data.message
      })
    }
  })

}
/**
 * 清空购物车
 * @param {*} params 
 * @param {*} cb 
 */
shop.clearCartGoods = function( params , cb ){
    http.doGet("/marketCart/clearCartGoods" , params , function( response ){
        cb(response.data)
    })
}
/**
 * 加载购物车商品列表
 * @param {*} params 
 * @param {*} cb 
 */
shop.getCartGoodList = function( params  ,cb ){
  http.doGet("/marketCart/getCartGoodList" ,params ,  function(response){
    cb(response.data)
  })
}

/**
 * 创建售后申请单
 * @param {*} data 
 * @param {*} cb 
 */
shop.createRefundOrder = function (data , cb) {
  http.doPost("/marketRefund/createRefundOrder" , data , function (response) {
    cb( response.data );
  })
}
//加载小店售后申请单列表
shop.getRefundOrderList = function name(params , cb) {

  http.doGet("/marketRefund/getRefundOrderList" , params , function (response) {
    cb(response.data)
    
  })
}

shop.getRefundDetail = function (params , cb) {
  http.doGet("/marketRefund/getRefundDetail" , params , function (response) {
    cb( response.data )
  })
}
shop.saveSendBackInfo = function (data , cb) {
  http.doPost("/marketRefund/saveSendBackInfo" , data , function (response) {
    cb( response.data )
  })
}

shop.setUserDefalutAddress = function (params , cb) {

  http.doGet("/marketAddress/setUserDefaultAddress" , params , function (response) {
    cb( response.data )
  })
  
}






api.product = product
api.refund = refund;

api.user = user;

api.retail = retail;
api.cash = cash;
api.setting = setting;
api.activity = activity;
api.article = article;
api.shop = shop;
api.coupou = coupou;

export default api;